package com.ctyon.common.binding;

import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.widget.ImageView;

//import com.ctyon.common.config.glid.GlideApp;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import com.ctyon.common.R;
import com.ctyon.common.config.glid.GlideApp;
import com.ctyon.common.util.DataUtil;

import java.net.URL;
import java.util.Date;

import androidx.annotation.Nullable;
import androidx.databinding.BindingAdapter;


/**
 * Created by Lee on 2018/12/31.
 */

public class CustomAttribute {

    /**
     * 《说明》：
     * 1. 方法名可与注解名一样，也可不一样
     * 2. 第一个参数必须是View，就是自定义属性所在的View
     * 3. 第二个参数就是自定义属性的值，与注解值对应。这是数组，可多个
     */

    //图片加载
    @BindingAdapter({"bind:showImg"})
    public static void showImg(ImageView imageView, Drawable imgRes) {
        GlideApp.with(imageView.getContext()).load(imgRes).into(imageView);
    }

    @BindingAdapter({"bind:showImgCircle"})
    public static void showImgCircle(ImageView imageView, Drawable imgRes) {
        GlideApp.with(imageView.getContext()).load(imgRes).error(R.drawable.icon).circleCrop().into(imageView);
    }

    private static boolean flag= true;
    @BindingAdapter({"bind:loadImg"})
    public static void loadImg(ImageView imageView, String imgUrl) {
        Log.e("android_imgUrl","imgUrl="+imgUrl+"imageView="+imageView);
        GlideApp.with(imageView.getContext()).load(imgUrl).error(R.drawable.icon).into(imageView);
    }

    @BindingAdapter({"bind:loadImgCircle"})
    public static void loadImgCircle(ImageView imageView, String imgUrl) {
        if (DataUtil.isEmptyAnd(imgUrl)){
            GlideApp.with(imageView.getContext()).load(R.drawable.icon).circleCrop().into(imageView);
        } else {
            GlideApp.with(imageView.getContext()).load(imgUrl).circleCrop().into(imageView);
        }
    }

}
